package com.fy.fyzf.presenter;

import com.fy.fyzf.api.SubscriberCallBack;
import com.fy.fyzf.base.BasePresenter;
import com.fy.fyzf.bean.AddHousingBean;
import com.fy.fyzf.bean.DeleteImgBean;
import com.fy.fyzf.bean.HouseDongBean;
import com.fy.fyzf.bean.HousingDetailBean;
import com.fy.fyzf.bean.HousingSearchBean;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.view.AddHouingCallBack;

import java.util.List;

import okhttp3.MultipartBody;

public class AddhousingPresenter extends BasePresenter<AddHouingCallBack> {

    public AddhousingPresenter(AddHouingCallBack view) {
        super(view);
    }

    public void fuzzyQueryFloor(String name){
        addSubscription(mApiService.fuzzyQueryFloor(name), new SubscriberCallBack<BaseData<List<HousingSearchBean>>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<List<HousingSearchBean>> response) {
                mView.fuzzyQueryFloorSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getFloorList(Integer id){
        addSubscription(mApiService.floorList(id), new SubscriberCallBack<BaseData<HouseDongBean>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<HouseDongBean> response) {
                mView.getFloorListSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });

    }

    public void upLoadImg(MultipartBody.Part body){
        addSubscription(mApiService.uploadImg(body), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.upLoadImgSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void addHousing(AddHousingBean addHousingBean){
        addSubscription(mApiService.housingAdd(addHousingBean), new SubscriberCallBack<BaseData> (mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.addHousingSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getHousingDetail(Integer id){
        addSubscription(mApiService.getHousingDetail(id), new SubscriberCallBack<BaseData<HousingDetailBean>> (mView,true) {
            @Override
            protected void onSuccess(BaseData<HousingDetailBean> response) {
                mView.getHousingDetailSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void editHousing(AddHousingBean addHousingBean){
        addSubscription(mApiService.housingEdit(addHousingBean), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.editHousingSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }
    public void deleteHousingImg(DeleteImgBean deleteImgBean){
        addSubscription(mApiService.delHousingImage(deleteImgBean), new SubscriberCallBack<BaseData>(mView, false) {
            @Override
            protected void onSuccess(BaseData response) {

            }

            @Override
            protected void onError() {

            }
        });
    }

    public void addRecommendHousing (AddHousingBean addHousingBean){
        addSubscription(mApiService.addRecommendHousing(addHousingBean), new SubscriberCallBack<BaseData> (mView,true) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.addHousingSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void deleteHousing(Integer id){
        addSubscription(mApiService.delHousing(id), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.deleteHousingSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }
}
